package com.java.test;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

import java.util.Date;

import org.apache.cxf.endpoint.Client;  
import com.java.entity.User;
import com.java.service.ICalculatorService;
import com.java.service.IUserService;  
  
public class MainClient1 {  
 
    public static void main(String[] args) throws Exception {  
        // 调用WebService  
        System.out.println("#############Client IUserService##############");  
        JaxWsProxyFactoryBean userFactory = new JaxWsProxyFactoryBean();  
        userFactory.setServiceClass(IUserService.class);  
        userFactory.setAddress("http://localhost:8080/SpringCxfServer/user");
        
        IUserService userService = (IUserService) userFactory.create(); 
        
        System.out.println("#############IUserService getUserByName##############");  
        User user = userService.getUserByName("hoojo");  
        System.out.println(user.toString());  
  
        System.out.println("#############IUserService sayHi##############");  
        userService.sayHi("undoner");  
        
        System.out.println("#############IUserService setUser##############");  
        user.setAddress(String.valueOf(new Date().toString()));
        userService.setUser(user);  
        
        
        // 调用WebService  
        System.out.println("#############Client ICalculatorService##############");  
        JaxWsProxyFactoryBean calculatorFactory = new JaxWsProxyFactoryBean();  
        calculatorFactory.setServiceClass(ICalculatorService.class);  
        calculatorFactory.setAddress("http://localhost:8080/SpringCxfServer/calculator");
        
        ICalculatorService calculatorService = (ICalculatorService) calculatorFactory.create();  
        
        System.out.println("#############ICalculatorService plus##############");  
        float res1 = calculatorService.plus(1, 2);
        System.out.println(res1);
        
        System.out.println("#############ICalculatorService minus##############");  
        float res3 = calculatorService.minus(1, 2);
        System.out.println(res3);
        
        System.out.println("#############ICalculatorService multiply##############");  
        float res4 = calculatorService.multiply(1, 2);
        System.out.println(res4);
        
        System.out.println("#############ICalculatorService divide##############");  
        float res2 = calculatorService.divide(1, 2);
        System.out.println(res2);
    }  
}  
